 <!DOCTYPE html>
 
<%@ page import="java.sql.*" %> 
<%@ page import="java.io.*" %> 
<%@ page import="java.util.Date" %> 
<%@ page import="java.text.DateFormat" %> 
<%@ page import="java.text.SimpleDateFormat" %> 


<% 
try {
	
	String connectionURL = "jdbc:mysql://localhost:3306/unilearn"; 
	
	int c_row_count = 0;
	Connection connection = null;
	Statement stmt = null;
	ResultSet rst=null;

	Class.forName("com.mysql.jdbc.Driver").newInstance(); 

	connection = DriverManager.getConnection(connectionURL, "root", "");
	stmt = connection.createStatement();
	
	if(!connection.isClosed())
	{
		
		
		DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		DateFormat dateFormat2 = new SimpleDateFormat("yyyy-MM-dd");
		DateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
		Date _now = new Date();
		
		//get session values
		String user_id = (String)session.getAttribute("UserID");
		String permission = (String)session.getAttribute("Permission");
		String first_name = (String)session.getAttribute("LastName");
		String last_name = (String)session.getAttribute("FirstName");
		String class_group_id = (String)session.getAttribute("ClassGroupID");
		
	
%>

<html lang="en">
<head>
<script type="text/javascript">
	function subjectValueAdd(sub_value)
	{
		//alert("aaa");
		
		var str_tmp = sub_value.value.split(";");
		//var s_id = document.getElementsByName("datSubjectID");
		//var s_code = document.getElementsByName("datSubjectCode");
		//var s_name = document.getElementsByName("datSubjectName");
		
		//alert(str_tmp[0]);
		document.getElementsByName("datSubjectID")[0].value = str_tmp[0];
		document.getElementsByName("datSubjectCode")[0].value = str_tmp[1];
		document.getElementsByName("datSubjectName")[0].value = str_tmp[2];
		
		
	}
</script>
<link rel="stylesheet" type="text/css" href="common.css">
<title>UniLearn System</title>
</head>
<body>
<form action="tu_select_student_list.jsp" method="post" name="entry" onSubmit="return validate(this)">
<table class="TblBody" style="width:720px">
	<tr>
		<td>
			<div class="contentb">
				<table width="100%">
                    <tr>
                        <td  style="background-color:#ccff99; font-size:20px; font-weight:bold; width:70%; height:30px">Unit Select</td>
						<!-- <td style="background-color:#ccff99; font-weight:bold;"><%= dateFormat2.format(_now) %>&nbsp;&nbsp; Time: <%= timeFormat.format(_now) %></td> -->
                    </tr>
					<tr>
                        <td colspan="2">
							<table>
								<tr>
									<td>
										<input type="hidden" name="datSubjectID" />
										<input type="hidden" name="datSubjectCode" />
										<input type="hidden" name="datSubjectName" />
										<%
											rst = stmt.executeQuery("SELECT s.subject_id, s.subject_code, s.subject_name FROM subject s, subject_mapping sm, user u " + 
																		"WHERE s.subject_id = sm.subject_id AND u.user_id = sm.user_id " +
																		"AND u.user_id = '" + user_id + "' AND u.user_type_id = 3");
										%>
										<select name="cboSubjectList" onchange="subjectValueAdd(this); this.form.submit();" width="350px"> <!-- onchange="this.form.submit();"-->
											<option value="0">SELECT ONE</option>
										<%
											while(rst.next())
											{	
												out.println("<option value='"+rst.getString("subject_id")+ ";" + rst.getString("subject_code") + ";" + rst.getString("subject_name") + "'>"+rst.getString("subject_code")+ "  " + rst.getString("subject_name")+"</option>");
											}
										%>
										</select>
									</td>
								</tr>
							</table>
                        </td>
					</tr>
				</table>
			</div>
		</td>
	</tr>
</table>
</form>
<%
}
	}catch(Exception ex){

		out.println(ex);
	}
%>
</body>
</html>